<?php 
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($_SERVER['DOCUMENT_ROOT']."/Modules/MF93FL27/modconf.mex");
MYTCONN();
	// --- Print Board Requests
	form_pr('bcm','','','post');
	// Show Title
	echo '<div class="title">Prémios | ';
	mn_field('button','ED','new_entry','Novo Premio','','','','" 
		onclick="modalwindow(\'Novo Premio\',\''.$MODURL.'frm_product.php\',620,380);'); 
	echo ' Estado: ';
	$Qur = "SELECT sttFlag AS ID, stt_Word AS NAME FROM hd_sysstatus WHERE stt_Sistema = 23";
	mn_field('select','ED','bcm_Status',2,$Qur,'','',''); 
	echo ' Loja: ';
	$Qur = "SELECT OriNumero AS ID, OriNombre AS NAME FROM origenes WHERE OriActivo = 1 AND OriTipo = 2";
	mn_field('select','ED','bcm_Origen0','',$Qur,'','',''); 
	echo ' Classe: ';
	$Qur = "SELECT chc_ID AS ID, chc_Name AS NAME FROM hc_class";
	mn_field('select','ED','bcm_Class','',$Qur,'','',''); 
	echo ' Por Periodo: ';
	mn_field('date','ED','StartTime',date("Y-m-01"),'8','8','','');
	echo ' a ';
	mn_field('date','ED','EndTime',date("Y-m-d"),'8','8','','');
	mn_field('button','ED','View','Consultar','','','','" 
		onclick="document.bcm.action=\''.$MODURL.'campaigns.mex\';
		subform(\'bcm\',\'CampaignPanel\');'); 
	//  Make Panel
	echo '</div>
	<div id="CampaignPanel"></div>'; 
	$RSGET = $GLOBALS['MYT']->db_array("SELECT 
		REF AS O_ID, 
		NAME AS COL1, 
		InternalRef AS COL2, 
		Description AS COL3, 
		IF(bpd_Map=1,'Produto','Servico') AS COL4
			FROM bonusproducts");
	$CARD = $RSGET[0]; ?>
<script charset="utf-8" type="text/javascript">
disableSelection(document.getElementById("CampaignPanel"));

Ext.onReady(function(){

    Ext.QuickTips.init();

    var myData = [
	<?php   
	for ($i=1;$i<=$CARD;$i++) { 
	echo "[{$i},{$RSGET[$i]['O_ID']},'{$RSGET[$i]['COL1']}','{$RSGET[$i]['COL2']}','{$RSGET[$i]['COL3']}','{$RSGET[$i]['COL4']}']";
		if ($i<$CARD) {
			echo ',';
		}
    } ?>
    ];

    var ds = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, [
               {name: 'id'},
			   {name: 'O_ID', type: 'int'},
               {name: 'COL1', type: 'string'},
               {name: 'COL2', type: 'string'},
               {name: 'COL3', type: 'string'},
			   {name: 'COL4', type: 'string'}
          ])
    });
    ds.loadData(myData);
    var colModel = new Ext.grid.ColumnModel([
        {header: "N", width: 80, sortable: true, locked:true, dataIndex: 'O_ID'},
        {header: "Tipo", width: 120, sortable: true, locked:true,dataIndex: 'COL4'},
        {header: "Referencia", width: 80, sortable: true, dataIndex: 'COL2'},
        {header: "Premio", width: 200, sortable: true, locked:true, dataIndex: 'COL1'},
        {header: "Descricao", width: 250, sortable: true, locked:true,dataIndex: 'COL3'}

    ]);
	
function ShowProp(id) { 
	var properties = new Ext.Window({
		title:'Dados do Premio',
		autoLoad: '<?php echo $MODURL;?>frm_product.php?PrdID='+id,
		modal:true,
		width:620,
		height:380,
		resizable:false
	});
	properties.show();
}

   var selmode = new Ext.grid.RowSelectionModel({});
   var Console = new Ext.grid.GridPanel({
	            ds: ds,
	            cm: colModel,
	            sm: selmode,
				listeners: {
	 				rowdblclick: function(ds, row) { 
					var record = ds.getStore().getAt(row);
  					var value = record.get('O_ID');	
					ShowProp(value);
					}
				},
	    height: 400,
	    border: true,
        renderTo: 'CampaignPanel'
    });
});
</script>
</form>